home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / simpsons.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  5KB  |  223 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3. #include "vidhrdw/konamiic.h"
  4. #include "cpu/konami/konami.h"
  5. #include "machine/eeprom.h"
  6.  
  7. /* from vidhrdw */
  8. extern void simpsons_video_banking( int select );
  9. extern unsigned char *simpsons_xtraram;
  10.  
  11. int simpsons_firq_enabled;
  12.  
  13. /***************************************************************************
  14.  
  15.   EEPROM
  16.  
  17. ***************************************************************************/
  18.  
  19. static int init_eeprom_count;
  20.  
  21.  
  22. static struct EEPROM_interface eeprom_interface =
  23. {
  24.     7,                /* address bits */
  25.     8,                /* data bits */
  26.     "011000",        /*  read command */
  27.     "011100",        /* write command */
  28.     0,                /* erase command */
  29.     "0100000000000",/* lock command */
  30.     "0100110000000" /* unlock command */
  31. };
  32.  
  33. void simpsons_nvram_handler(void *file,int read_or_write)
  34. {
  35.     if (read_or_write)
  36.         EEPROM_save(file);
  37.     else
  38.     {
  39.         EEPROM_init(&eeprom_interface);
  40.  
  41.         if (file)
  42.         {
  43.             init_eeprom_count = 0;
  44.             EEPROM_load(file);
  45.         }
  46.         else
  47.             init_eeprom_count = 10;
  48.     }
  49. }
  50.  
  51. READ_HANDLER( simpsons_eeprom_r )
  52. {
  53.     int res;
  54.  
  55.     res = (EEPROM_read_bit() << 4);
  56.  
  57.     res |= 0x20;//konami_eeprom_ack() << 5; /* add the ack */
  58.  
  59.     res |= readinputport( 5 ) & 1; /* test switch */
  60.  
  61.     if (init_eeprom_count)
  62.     {
  63.         init_eeprom_count--;
  64.         res &= 0xfe;
  65.     }
  66.     return res;
  67. }
  68.  
  69. WRITE_HANDLER( simpsons_eeprom_w )
  70. {
  71.     if ( data == 0xff )
  72.         return;
  73.  
  74.     EEPROM_write_bit(data & 0x80);
  75.     EEPROM_set_cs_line((data & 0x08) ? CLEAR_LINE : ASSERT_LINE);
  76.     EEPROM_set_clock_line((data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
  77.  
  78.     simpsons_video_banking( data & 3 );
  79.  
  80.     simpsons_firq_enabled = data & 0x04;
  81. }
  82.  
  83. /***************************************************************************
  84.  
  85.   Coin Counters, Sound Interface
  86.  
  87. ***************************************************************************/
  88.  
  89. WRITE_HANDLER( simpsons_coin_counter_w )
  90. {
  91.     /* bit 0,1 coin counters */
  92.     coin_counter_w(0,data & 0x01);
  93.     coin_counter_w(1,data & 0x02);
  94.     /* bit 2 selects mono or stereo sound */
  95.     /* bit 3 = enable char ROM reading through the video RAM */
  96.     K052109_set_RMRD_line((data & 0x08) ? ASSERT_LINE : CLEAR_LINE);
  97.     /* bit 4 = INIT (unknown) */
  98.     /* bit 5 = enable sprite ROM reading */
  99.     K053246_set_OBJCHA_line((~data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
  100. }
  101.  
  102. READ_HANDLER( simpsons_sound_interrupt_r )
  103. {
  104.     cpu_cause_interrupt( 1, 0xff );
  105.     return 0x00;
  106. }
  107.  
  108. READ_HANDLER( simpsons_sound_r )
  109. {
  110.     /* If the sound CPU is running, read the status, otherwise
  111.        just make it pass the test */
  112.     if (Machine->sample_rate != 0)     return K053260_r(2 + offset);
  113.     else
  114.     {
  115.         static int res = 0x80;
  116.  
  117.         res = (res & 0xfc) | ((res + 1) & 0x03);
  118.         return offset ? res : 0x00;
  119.     }
  120. }
  121.  
  122. /***************************************************************************
  123.  
  124.   Speed up memory handlers
  125.  
  126. ***************************************************************************/
  127.  
  128. READ_HANDLER( simpsons_speedup1_r )
  129. {
  130.     unsigned char *RAM = memory_region(REGION_CPU1);
  131.  
  132.     int data1 = RAM[0x486a];
  133.  
  134.     if ( data1 == 0 )
  135.     {
  136.         int data2 = ( RAM[0x4942] << 8 ) | RAM[0x4943];
  137.  
  138.         if ( data2 < memory_region_length(REGION_CPU1) )
  139.         {
  140.             data2 = ( RAM[data2] << 8 ) | RAM[data2 + 1];
  141.  
  142.             if ( data2 == 0xffff )
  143.                 cpu_spinuntil_int();
  144.  
  145.             return RAM[0x4942];
  146.         }
  147.  
  148.         return RAM[0x4942];
  149.     }
  150.  
  151.     if ( data1 == 1 )
  152.         RAM[0x486a]--;
  153.  
  154.     return RAM[0x4942];
  155. }
  156.  
  157. READ_HANDLER( simpsons_speedup2_r )
  158. {
  159.     int data = memory_region(REGION_CPU1)[0x4856];
  160.  
  161.     if ( data == 1 )
  162.         cpu_spinuntil_int();
  163.  
  164.     return data;
  165. }
  166.  
  167. /***************************************************************************
  168.  
  169.   Banking, initialization
  170.  
  171. ***************************************************************************/
  172.  
  173. static void simpsons_banking( int lines )
  174. {
  175.     unsigned char *RAM = memory_region(REGION_CPU1);
  176.     int offs = 0;
  177.  
  178.     switch ( lines & 0xf0 )
  179.     {
  180.         case 0x00: /* simp_g02.rom */
  181.             offs = 0x10000 + ( ( lines & 0x0f ) * 0x2000 );
  182.         break;
  183.  
  184.         case 0x10: /* simp_p01.rom */
  185.             offs = 0x30000 + ( ( lines & 0x0f ) * 0x2000 );
  186.         break;
  187.  
  188.         case 0x20: /* simp_013.rom */
  189.             offs = 0x50000 + ( ( lines & 0x0f ) * 0x2000 );
  190.         break;
  191.  
  192.         case 0x30: /* simp_012.rom ( lines goes from 0x00 to 0x0c ) */
  193.             offs = 0x70000 + ( ( lines & 0x0f ) * 0x2000 );
  194.         break;
  195.  
  196.         default:
  197.             logerror("PC = %04x : Unknown bank selected (%02x)\n", cpu_get_pc(), lines );
  198.         break;
  199.     }
  200.  
  201.     cpu_setbank( 1, &RAM[offs] );
  202. }
  203.  
  204. void simpsons_init_machine( void )
  205. {
  206.     unsigned char *RAM = memory_region(REGION_CPU1);
  207.  
  208.     konami_cpu_setlines_callback = simpsons_banking;
  209.  
  210.     paletteram = &RAM[0x88000];
  211.     simpsons_xtraram = &RAM[0x89000];
  212.     simpsons_firq_enabled = 0;
  213.  
  214.     /* init the default banks */
  215.     cpu_setbank( 1, &RAM[0x10000] );
  216.  
  217.     RAM = memory_region(REGION_CPU2);
  218.  
  219.     cpu_setbank( 2, &RAM[0x10000] );
  220.  
  221.     simpsons_video_banking( 0 );
  222. }
  223.